package com.global.gbinventory.main.view;

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

//import utils.SETUP_TYPE;
//
//import controllers.Controller;
//import controllers.DatabaseController;
//import controllers.PSKController;
import java.awt.Color;

public class MainFrame{

	private JFrame frame;
	private JDesktopPane desktopPane;

	
	private JMenuItem itemSetupMerek;
	private JMenuItem itemSetupSatuan;
	private JMenuItem itemSetupGudang;
	private JMenuItem itemSetupGrup;
	private JMenuItem itemSetupBarang;
	private JMenuItem itemSetupPelanggan;
	private JMenuItem itemSetupKaryawan;
	private JMenuItem itemSetupSupplier;
	
	private JMenuItem itemDaftarBarang;
	private JMenuItem itemDaftarPelanggan;
	private JMenuItem itemDaftarKaryawan;
	private JMenuItem itemDaftarSupplier;
	
	/**
	 * Create the application.
	 */
	public MainFrame() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setExtendedState(Frame.MAXIMIZED_BOTH);
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
		Container content = frame.getContentPane();
		desktopPane = new JDesktopPane();
		desktopPane.setBackground(Color.WHITE);
		content.add(desktopPane, BorderLayout.CENTER);
		
		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		JMenu menuFile = new JMenu("File");
		menuBar.add(menuFile);
		
		JMenuItem mntmItem = new JMenuItem("Item1");
		menuFile.add(mntmItem);
		
		JMenuItem itemExit = new JMenuItem("Exit");
		itemExit.addActionListener(new ExitListener());
		menuFile.add(itemExit);
		
		JMenu mnMenu_1 = new JMenu("Menu2");
		menuBar.add(mnMenu_1);
		
		JMenuItem mntmItem_2 = new JMenuItem("Item1");
		mnMenu_1.add(mntmItem_2);
		
		JMenuItem mntmItem_3 = new JMenuItem("Item2");
		mnMenu_1.add(mntmItem_3);
		
		JMenu menuListing = new JMenu("Listing");
		menuBar.add(menuListing);
		
		itemDaftarBarang = new JMenuItem("Daftar Barang");
		itemDaftarBarang.setActionCommand("itemDaftarBarang");
		menuListing.add(itemDaftarBarang);
		
		itemDaftarPelanggan = new JMenuItem("Daftar Pelanggan");
		itemDaftarPelanggan.setActionCommand("itemDaftarPelanggan");
		menuListing.add(itemDaftarPelanggan);
		
		itemDaftarKaryawan = new JMenuItem("Daftar Karyawan");
		itemDaftarKaryawan.setActionCommand("itemDaftarKaryawan");
		menuListing.add(itemDaftarKaryawan);
		
		itemDaftarSupplier = new JMenuItem("Daftar Supplier");
		itemDaftarSupplier.setActionCommand("itemDaftarSupplier");
		menuListing.add(itemDaftarSupplier);
		
		JMenu menuSetup = new JMenu("Setup");
		menuBar.add(menuSetup);
		
		JMenu subMenuSetupBarang = new JMenu("Barang");
		menuSetup.add(subMenuSetupBarang);
		
		//Create Sub MenuItem from Barang
		itemSetupMerek = new JMenuItem("Merek");
		itemSetupMerek.setActionCommand("itemSetupMerek");
		subMenuSetupBarang.add(itemSetupMerek);
		
		itemSetupSatuan = new JMenuItem("Satuan");
		itemSetupSatuan.setActionCommand("itemSetupSatuan");
		subMenuSetupBarang.add(itemSetupSatuan);
		
		itemSetupGudang = new JMenuItem("Gudang");
		itemSetupGudang.setActionCommand("itemSetupGudang");
		subMenuSetupBarang.add(itemSetupGudang);
		
		itemSetupGrup = new JMenuItem("Grup");
		itemSetupGrup.setActionCommand("itemSetupGrup");
		subMenuSetupBarang.add(itemSetupGrup);
		
		itemSetupBarang = new JMenuItem("Barang");
		itemSetupBarang.setActionCommand("itemSetupBarang");
		subMenuSetupBarang.add(itemSetupBarang);
		
		JMenu subMenuSetupData = new JMenu("Data");
		menuSetup.add(subMenuSetupData);
		
		itemSetupPelanggan = new JMenuItem("Pelanggan");
		itemSetupPelanggan.setActionCommand("itemSetupPelanggan");
		subMenuSetupData.add(itemSetupPelanggan);
		
		itemSetupKaryawan = new JMenuItem("Karyawan");
		itemSetupKaryawan.setActionCommand("itemSetupKaryawan");
		subMenuSetupData.add(itemSetupKaryawan);
		
		itemSetupSupplier = new JMenuItem("Supplier");
		itemSetupSupplier.setActionCommand("itemSetupSupplier");
		subMenuSetupData.add(itemSetupSupplier);
		
		JMenu mnMenu_4 = new JMenu("Menu5");
		menuBar.add(mnMenu_4);
		
		JMenuItem mntmItem_8 = new JMenuItem("Item1");
		mnMenu_4.add(mntmItem_8);
		
		JMenuItem mntmItem_9 = new JMenuItem("Item2");
		mnMenu_4.add(mntmItem_9);
		
	}
	
	public void displayFrame(){
		frame.setVisible(true);
	}
	
	public void addFrameToDesktopPane(JInternalFrame frame){
		desktopPane.add(frame);
	}
	
	public void removeFrameFromDesktopPane(JInternalFrame frame){
		desktopPane.remove(frame);
	}
	
	public void addItemSetupMerekListener(ActionListener l){
		itemSetupMerek.addActionListener(l);
	}
	
	public void addItemSetupSatuanListener(ActionListener l){
		itemSetupSatuan.addActionListener(l);
	}
	
	public void addItemSetupGudangListener(ActionListener l){
		itemSetupGudang.addActionListener(l);
	}
	
	public void addItemSetupGrupListener(ActionListener l){
		itemSetupGrup.addActionListener(l);
	}
	
	public void addItemSetupBarangListener(ActionListener l){
		itemSetupBarang.addActionListener(l);
	}
	
	public void addItemSetupKaryawanListener(ActionListener l){
		itemSetupKaryawan.addActionListener(l);
	}
	
	public void addItemSetupPelangganListener(ActionListener l){
		itemSetupPelanggan.addActionListener(l);
	}
	
	public void addItemSetupSupplierListener(ActionListener l){
		itemSetupSupplier.addActionListener(l);
	}
	
	public void addItemDaftarBarangListener(ActionListener l){
		itemDaftarBarang.addActionListener(l);
	}
	
	public void addItemDaftarKaryawanListener(ActionListener l){
		itemDaftarKaryawan.addActionListener(l);
	}
	
	public void addItemDaftarPelangganListener(ActionListener l){
		itemDaftarPelanggan.addActionListener(l);
	}
	
	public void addItemDaftarSupplierListener(ActionListener l){
		itemDaftarSupplier.addActionListener(l);
	}

	class SetupBarangListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
		}
		
	}
	
	class DaftarPelangganListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
//			if(pelangganController == null){
//				pelangganController = new PSKController(SETUP_TYPE.PELANGGANs, dbController);
//			}
//			JInternalFrame daftarPelanggan = new PelangganKaryawanList(pelangganController, desktopPane);
//			daftarPelanggan.setLocation(0, 0);
//			desktopPane.add(daftarPelanggan);
//			try {
//				daftarPelanggan.setMaximum(true);
//			} catch (PropertyVetoException e1) {
//				e1.printStackTrace();
//			}
//			daftarPelanggan.moveToFront();
		}
		
	}
	
	class DaftarKaryawanListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
//			if(karyawanController == null){
//				karyawanController = new PSKController(SETUP_TYPE.KARYAWANs, dbController);
//			}
//			JInternalFrame daftarKaryawan = new PelangganKaryawanList(karyawanController, desktopPane);
//			daftarKaryawan.setLocation(0, 0);
//			desktopPane.add(daftarKaryawan);
//			try {
//				daftarKaryawan.setMaximum(true);
//			} catch (PropertyVetoException e1) {
//				e1.printStackTrace();
//			}
//			daftarKaryawan.moveToFront();
		}
		
	}
	
	class DaftarSupplierListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
//			if(supplierController == null){
//				supplierController = new PSKController(SETUP_TYPE.SUPPLIERs, dbController);
//			}
//			JInternalFrame daftarSupplier = new SupplierList(supplierController, desktopPane);
//			daftarSupplier.setLocation(0, 0);
//			desktopPane.add(daftarSupplier);
//			try {
//				daftarSupplier.setMaximum(true);
//			} catch (PropertyVetoException e1) {
//				e1.printStackTrace();
//			}
//			daftarSupplier.moveToFront();
		}
		
	}
	
	class DafterBarangListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
		}
		
	}
	
	class ExitListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
		}
		
	}
}
